package com.project.managementpaltform.mapper;

import com.project.managementpaltform.entity.Equipment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EquipmentMapper {

    /**
     * 查找年度设备档案
     * */
    @Select("SELECT * FROM equipment")
    @Results({
            @Result(column = "Management number",property = "ManagementNumber"),
            @Result(column = "Equipment number",property = "EquipmentNumber"),
            @Result(column = "Equipment name",property = "EquipmentName"),
            @Result(column = "Model number",property = "ModelNumber"),
            @Result(column = "Original value",property = "OriginalValue"),
            @Result(column = "Funding date",property = "FundingDate"),
            @Result(column = "Manufacturing unit",property = "ManufacturingUnit"),
            @Result(column = "Management classifiction",property = "ManagementClassifiction"),
            @Result(column = "Equipment type",property = "EquipmentType"),
            @Result(column = "Verification period",property = "VerificationPeriod"),
            @Result(column = "Verification unit",property = "VerificationUnit"),
            @Result(column = "Term of validity",property = "TermOfValidity"),
            @Result(column = "State",property = "State"),
            @Result(column = "Delivery time",property = "DeliveryTime"),
            @Result(column = "Storage time",property = "StorageTime"),
            @Result(column = "Project",property = "Project")
    })
    List<Equipment> findWholeEquipment();

    /**
     * 生成设备检定/校准计划
     * */
    @Select("SELECT Verification period,Verification unit FROM equipment WHERE EquipmentNumber=#{EquipmentNumber}")
    @Results({
            @Result(column = "Verification period",property = "VerificationPeriod"),
            @Result(column = "Verification unit",property = "VerificationUnit")
    })
    Equipment queryVerificationExcel(String EquipmentNumber);

    /**
     * 查看当前设备使用情况
     * */
    @Select("SELECT State FROM equipment WHERE Equipment number=#{EquipmentNumber}")
    @Results({
            @Result(column = "State",property = "State")
    })
    Equipment queryStatesByEquipmentNumber(String EquipmentNumber);

    /**
     * 根据设备名称找设备编号
     * */
    @Select("SELECT Equipment number FROM equipment WHERE Equipment name=#{EquipmentName}")
    @Results({
            @Result(column = "Equipment number",property = "EquipmentNumber")
    })
    Equipment queryEquipmentNumberByEquipmentName(String EquipmentName);

    /**
     * 项目选取设备更新
     * */
    @Update("UPDATE equipment SET Project = #{Project,jdbcType=VARCHAR}, WHERE Equipment name=#{EquipmentName,jdbcType=VARCHAR}")
    int updateProjectByEquipment(Equipment equipment);

    /**-+
     * 插入新设备
     * @param EquipmentNumber 设备编号
     *  @param EquipmentName 设备名称
     * @param VerificationRecord 检定记录
     * */
    @Insert("INERT INTO record (Equipment number,Equipment number,Verification record)" +
            " VALUES(#{EquipmentNumber},#{EquipmentName},#{VerificationRecord})")
    int insertRecord(@Param("Equipment number")String EquipmentNumber,
                     @Param("Equipment number")String EquipmentName,
                     @Param("Verification record") String VerificationRecord);
}
